<?php

$str = '21289';

$arr = str_split($str);

sort($arr);
var_dump($arr);
echo "<br><br>";

for ($i = 1; $i <= count($arr); $i++) {

	$total += $tmp;
	$result[] = $tmp;
}

$a = getCombinationToString($arr, 2);
$lian = array(2 => array('01', '09', '12', '23', '34', '45', '56', '67', '78', '89'),
	3 => array('012', '123', '234', '345', '456', '567', '678', '789', '089', '019'),
	4 => array('0123', '1234', '2345', '3456', '4567', '5678', '6789', '7890', '8901', '9012'),
	5 => array('01234', '12345', '23456', '34567', '45678', '56789', '67890', '78901', '89012', '90123'));
var_dump($a);

$b = array_intersect($a, $lian[2]);
echo "<br><br>";
var_dump($b);
function getCombinationToString($arr, $m) {
	$result = array();
	if ($m == 1) {
		return $arr;
	}

	if ($m == count($arr)) {
		$result[] = implode('', $arr);
		return $result;
	}

	$temp_firstelement = $arr[0];
	unset($arr[0]);
	$arr = array_values($arr);
	$temp_list1 = getCombinationToString($arr, ($m - 1));

	foreach ($temp_list1 as $s) {
		$s = $temp_firstelement . '' . $s;
		$result[] = $s;
	}
	unset($temp_list1);

	$temp_list2 = getCombinationToString($arr, $m);
	foreach ($temp_list2 as $s) {
		$result[] = $s;
	}
	unset($temp_list2);

	return $result;
}
